package co.edu.unal.bioingenium.kbmed.web.beans;

import co.edu.unal.bioingenium.kbmed.retrieval.knowledge.process.RetrieveService;
import co.edu.unal.bioingenium.kbmed.retrieval.vo.RelevantDocument;
import co.edu.unal.bioingenium.kbmed.web.util.FacesUtils;
import java.io.Serializable;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Luis A Riveros
 */
public class QueryBean implements Serializable {

    private RetrieveService retrieveService = RetrieveService.getInstance();
    private String queryStr;

    /** Creates a new instance of QueryBean */
    public QueryBean() {
        queryStr = "";
//        retrieve();

    }

    /**
     * 
     * @return
     */
    public String getQueryStr() {
        return queryStr;
    }

    /**
     * 
     * @param queryStr
     */
    public void setQueryStr(String queryStr) {
        this.queryStr = queryStr;
    }

    public void retrieve() {
        Logger.getLogger(QueryBean.class.getName()).log(Level.INFO, "Run query for input: {0}", queryStr);
        long start, end;
        start = System.currentTimeMillis();
        List<RelevantDocument> results = retrieveService.retrieveByConcepts(queryStr);
        end = System.currentTimeMillis() - start;
        ResultsBean resultsBean = (ResultsBean) FacesUtils.getManagedBean("results");
        resultsBean.setResultsList(results);
        resultsBean.setResultsInfo(results.size() + " in " + end + " miliseconds");
        NavigationBean navigationBean = (NavigationBean) FacesUtils.getManagedBean("navigation");
        navigationBean.initVisualizationData(results, retrieveService.getCollectionData().getConceptCorpus());
    }
}
